<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>人员修改</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    {CSS href="__ADDONSTATIC__css/font.css" /}
    {CSS href="__ADDONSTATIC__css/xadmin.css" /}
    {js href='__ADDONSTATIC__js/jquery-3.2.1.min.js' /}

    {js href='__ADDONSTATIC__js/xadmin.js' /}
    {js href='__ADDONSTATIC__js/util.js' /}
    {js href='__ADDONSTATIC__lib/layui/layui.js' /}
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="name" class="layui-form-label">
                  <span class="x-red">*</span>姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" required="" lay-verify="required" value="{$member.name}" autocomplete="off" class="layui-input">
                  <input type="hidden" id="id" name="id" required="" value="{$member.id}" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  <span class="x-red">*</span>手机
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="phone" name="phone" required="" lay-verify="phone" value="{$member.phone}"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label"><span class="x-red">*</span>角色</label>
              <div class="layui-input-block" id="part">
                  {foreach name="part" item="value"}
                  {if  condition="$value['checked']"}
                  <input   lay-filter="part" type="checkbox"  name="{$value['id']}" lay-skin="primary" title="{$value['name']}" checked="">
                  {else/}
                  <input   lay-filter="part" type="checkbox"  name="{$value['id']}" lay-skin="primary" title="{$value['name']}">
                  {/if}
                  {/foreach}
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  增加
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form
          ,layer = layui.layer;
            var part = [];
            $("#part input").each(function(){
                if(this.checked==true){
                   part.push(this.name);
                }
            });
            //部门复选框
        form.on('checkbox(part)',function(data){
            if(data.elem.checked){
                part.push(data.elem.name);
            }else{
                part.splice($.inArray(data.elem.name,part),1);
            }
        });

          //监听提交
          form.on('submit(add)', function(data){
              data.field.part = part;
              console.log(data.field);
              //发异步，把数据提交给php
              ajaxUrl('{:addonUrl('Member/updateMember')}',data.field
                      ,function(data){
                    layer.alert(data.message, {},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                    });
              });
            return false;
          });
          
          
        });
    </script>
  </body>

</html>